select * from trb_cobranca_amigavel where cob_tipo = 8

select * from trb_iptu where imv_cod in ( select imv_cod from trb_imovel where len(imv_inscricao) > 14 )

select imv_inscricao/*, len(imv_inscricao) as tam */from trb_imovel where len(imv_inscricao) > 14 union
select imv_inscricao/*, len(imv_inscricao) */from trb_imovel where len(imv_inscricao) < 14
SELECT B.IMV_INSCRICAO, * 
	FROM TRB_COBRANCA_AMIGAVEL A 
	JOIN TRB_IPTU_EXPORTAR_VI  B ON B.IMV_COD = A.IMV_COD
	WHERE A.COB_TIPO = 8 

SELECT COUNT(*) FROM TRB_IPTU_EXPORTAR_VI

CREATE FUNCTION DBO.TRB_INSCRICAO_NOTIFICACAO_FN( @IMV_COD INT, @ANO_COD INT )
RETURNS CHAR(1) AS
BEGIN
	DECLARE @R CHAR(1)
    IF EXISTS ( SELECT * FROM TRB_COBRANCA_AMIGAVEL C JOIN TRB_IPTU I ON I.IMV_COD = C.IMV_COD 
				JOIN TRB_IMOVEL M ON M.IMV_COD = C.IMV_COD 
				WHERE C.IMV_COD = @IMV_COD AND COB_TIPO = 8 AND CAM_SITUACAO = 'N' AND I.EXE_ANO = @ANO_COD AND LEN(IMV_INSCRICAO) = 14 )
		SET @R = '*'
	ELSE
		SET @R = ''
	RETURN @R
END

TRB_IPTU_EXPORTAR_VI

CREATE INDEX TRB_COBRANCA_AMIGAVEL_IX ON TRB_COBRANCA_AMIGAVEL (IMV_COD)